<template>
	<div>
		<el-row :gutter="24" v-if="tableFlog">
			<el-col :span="24">
				<el-row :gutter="24" v-if="true">
					<el-col :span="1" style="margin-right:10px;">
						<p class="queryLabel">盘点日期:</p>
					</el-col>
					<el-col :span="7">
						<el-date-picker v-model="data.firstStart" size="small" style="width:45%;" type="date" clearable placeholder="盘点日期">
						</el-date-picker>
						至
						<el-date-picker v-model="data.firstStarts" size="small" style="width:45%;" type="date" clearable placeholder="盘点日期">
						</el-date-picker>
					</el-col>
					<el-col :span="1" style="margin-right:5px;">
						<p class="queryLabel">所在仓库:</p>
					</el-col>
					<el-col :span="4">
						<el-select v-model="conditions.warehouse" left size="small" placeholder="请选择仓库" clearable>
							<el-option v-for="item in warehouse" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" style="margin-right:5px;">
						<p class="queryLabel">盘点结果:</p>
					</el-col>
					<el-col :span="3">
						<el-select v-model="conditions.result" left size="small" placeholder="请选择盘点结果" clearable>
							<el-option v-for="item in inventoryResult" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" style="padding-left: 0px;text-align: right">
						<el-button type="primary" size="small" v-on:click='companyQuery'>查询</el-button>
					</el-col>
					<el-col :span="1" style="padding-left: 0px;text-align: right">
						<el-button type="primary" size="small" v-on:click='add'>新增</el-button>
					</el-col>
					<!--<el-col :span="2" style="padding-left: 0px;text-align: right">
						<el-button type="primary" size="small" v-on:click='makeResult'>盘点结果处理</el-button>
					</el-col>-->
					<el-col :span="2" style="padding-left: 0px;text-align: right">
						<el-button type="primary" size="small" v-on:click='lock'>确认</el-button>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-table :data="tableData.dataList" border style="width: 100%;align-content: center;" :row-class-name="tableRowClassName" @selection-change="makeHandleSelectionChange">
							<el-table-column type="selection" width="60">
							</el-table-column>
							<el-table-column label="任务名称" prop="taskName">
							</el-table-column>
							<el-table-column label="任务状态" prop="taskStatus" :formatter="taskStatusCov">
							</el-table-column>
							<el-table-column label="盘点位置" align="right" prop="locationName">
							</el-table-column>
							<el-table-column label="盘点车辆总数" align="right" prop="carCount">
							</el-table-column>
							<el-table-column label="盘点结果" align="right" prop="result" :formatter="resultCov">
							</el-table-column>
							<el-table-column label="盘点日期" align="right" prop="inventoryDate">
							</el-table-column>

							<el-table-column label="盘点结果原因" align="right" prop="resultReason">
							</el-table-column>
							<el-table-column label="操作" align="right" width="80">
								<template scope="scope">
									<el-tooltip class="item" effect="light" content="车辆列表" placement="top">
										<el-button type="primary" size="mini" icon="setting" @click.native.prevent="info(scope.$index)"></el-button>
									</el-tooltip>
								</template>
							</el-table-column>
						</el-table>
						<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
						</el-pagination>
					</el-col>
				</el-row>
			</el-col>
		</el-row>
		<el-row :gutter="24" v-if="!tableFlog">
			<el-row :gutter="24">
				<el-col :span="1" style="margin-left:15px;">
					<p class="queryLabel">车架号:</p>
				</el-col>
				<el-col :span="4">
					<el-input size="small" v-model="conditionCar.vin" placeholder="请输入车架号">
					</el-input>
				</el-col>
				<el-col :span="1" style="margin-right:0px;">
					<p class="queryLabel">车型:</p>
				</el-col>
				<el-col :span="4" size="small" style="margin-right:0px;">
					<el-input placeholder="请选择车型" icon="search" v-model="conditionCar.carModel" :on-icon-click="handleIconClick">
					</el-input>
				</el-col>
				<el-col :span="12" style="padding-left: 0px;text-align: right">
					<el-button type="primary" size="small" v-on:click='inventoryCarQuery'>查询</el-button>
					<!--<el-button type="primary" size="small" v-on:click='addCar'>添加车辆</el-button>
					<el-button type="primary" size="small" v-on:click='addPrient'>加入打印列表</el-button>
					<el-button type="primary" size="small" v-on:click='prientOrder'>打印盘点单</el-button>-->
					<el-button type="primary" size="small" v-on:click='downloadOrder' v-if="statusFlog">导出盘点单</el-button>
					<el-button type="primary" size="small" v-on:click='addInventoryResultRight' v-if="statusFlog">正常盘点结果录入</el-button>
					<el-button type="primary" size="small" v-on:click='addDifference' v-if="statusFlog">盘亏盘点结果录入</el-button>
					<div style="clear: both;float: left" v-if="statusFlog">
						<el-upload :action="action" :data="upData" name="upExecl" :on-progress="process" :on-error="error" :on-success="success">
							<el-button size="small" type="primary">上传车辆</el-button>
							<span slot="tip">只能上传xlsx文件</span>
						</el-upload>
					</div>
					<!--<el-button type="primary" size="small" v-on:click='addDifference'>添加单车盘点差异原因</el-button>-->
				</el-col>
				<el-col :span="1" style="padding-left: 0px;text-align: right">
					<el-button type="primary" icon="caret-left" size="small" v-on:click='buckList'>返回</el-button>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="24" style="margin-left:15px;">
					<el-table :data="tableDatas.dataList" border style="width: 100%;align-content: center;" @selection-change="carHandleSelectionChange">
						<el-table-column type="selection" width="60">
						</el-table-column>
						<el-table-column label="VIN" prop="vin">
						</el-table-column>
						<el-table-column label="车型" align="right" prop="carModel">
						</el-table-column>
						<el-table-column label="仓库" align="right" prop="warehouse">
						</el-table-column>
						<el-table-column label="配置" align="right" prop="configureName">
						</el-table-column>
						<el-table-column label="差异类型" align="right" prop="differenceType" width="100">
						</el-table-column>
						<el-table-column label="差异原因" align="right" prop="resultReason" width="100">
						</el-table-column>
						<el-table-column label="确认人" align="right" prop="inventoryPerson" width="100">
						</el-table-column>
						<el-table-column label="确认时间" align="right" prop="inventoryTime">
						</el-table-column>
					</el-table>
					<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChanges" :current-page="CurentPages" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableDatas.total">
					</el-pagination>
				</el-col>
			</el-row>
		</el-row>
		<!--新增盘点任务-->
		<el-dialog title="盘点任务新增" v-model="comFormShow" size="tiny">
			<el-form :model="comFormData" ref="comForm" :rules="Rule" label-width="150px">
				<el-col :span="24">
					<el-form-item label="任务名称：" prop="taskName" required>
						<el-input size="small" v-model="comFormData.taskName"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所在仓库：" prop="locationId" required>
						<el-select v-model="warehouseID" left size="small" placeholder="请选择仓库" @change="locationChange">
							<el-option v-for="item in warehouse" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所在单位：" prop="locationId" required>
						<el-input placeholder="请选择单位" size="small" icon="search" v-model="companyID" :on-icon-click="handleIconClickCompany" @blur="locationChange">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="盘点车辆总数：" prop="carCount" required>
						<el-input size="small" v-model="comFormData.carCount" readonly></el-input>
					</el-form-item>
				</el-col>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="comFormShow=false">取 消</el-button>
				<el-button type="primary" v-on:click='save'>提 交</el-button>
			</div>
		</el-dialog>
		<!--填写盘点结果-->
		<el-dialog title="盘点结果处理" v-model="makeComFormShow" size="tiny">
			<el-form :model="comFormData" ref="makeComForm" :rules="RuleInventory" label-width="150px">
				<el-col :span="24">
					<el-form-item label="盘点结果：" prop="result" required>
						<el-select v-model="comFormData.result" left size="small" placeholder="请选择盘点结果">
							<el-option v-for="item in inventoryResult" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="盘点日期：" prop="inventoryDate" required>
						<el-date-picker size="small" style="width: 150px;" v-model="comFormData.inventoryDate" format="yyyy-MM-dd" :editable=false type="date">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="盘点结果原因：" prop="resultReason" required>
						<el-input size="small" v-model="comFormData.resultReason"></el-input>
					</el-form-item>
				</el-col>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="makeComFormShow=false">取 消</el-button>
				<el-button type="primary" v-on:click='update'>提 交</el-button>
			</div>
		</el-dialog>
		<el-dialog title="单车差异原因" v-model="makeComFormReasonShow" size="tiny">
			<el-form :model="comFormReason" ref="makeComFormReasonShow" :rules="RuleInventory" label-width="100px">
				<el-col :span="24">
					<el-form-item label="差异原因：" prop="differenceReason" required>
						<el-input type="textarea" :rows="3" size="small" v-model="comFormReason.reason"></el-input>
					</el-form-item>
				</el-col>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="makeComFormReasonShow=false">取 消</el-button>
				<el-button type="primary" v-on:click='addDifferenceReason'>提 交</el-button>
			</div>
		</el-dialog>
		<el-dialog title="待打印车辆" v-model="prientFormShow" size="tiny">
			<el-table :data="prientList" border style="align-content: center;">
				<el-table-column prop="vin" label="VIN">
				</el-table-column>
				<el-table-column prop="configureName" label="配置名称">
				</el-table-column>
				<el-table-column prop="differenceReason" label="差异原因">
				</el-table-column>
			</el-table>
			<div slot="footer" class="dialog-footer">
				<el-button @click="prientFormShow = false">取 消</el-button>
				<el-button type="primary" v-on:click='savePrient'>提 交</el-button>
			</div>
		</el-dialog>
		<el-dialog title="选择车型" v-model="showStart" size="small">
			<el-row :gutter="24">
				<el-col :span="11" style="margin-left:5px;">
					<el-input size="small" v-model="dictTreeSearchValue" placeholder="请输入内容" icon="search" @click="searchTree"></el-input>
				</el-col>
				<el-col :span="11" style="margin-left:5px;">
				</el-col>
				<el-col :span="24" style="margin-left:5px;">
					<div style="height: 3em;"></div>
				</el-col>
				<el-col :span="24" style="margin-left:5px;">
					<el-tree :data="paramTreeData" :filter-node-method="filterNode" :highlight-current=true :props="defaultProps" accordion @node-click="handleNodeClick" :auto-expand-parent=false ref="dictTree" node-key="id"></el-tree>
				</el-col>
			</el-row>
			<div slot="footer" class="dialog-footer">
				<el-button @click="showStart = false">取 消</el-button>
				<el-button type="primary" @click="saveCarSerices()">提 交</el-button>
			</div>
		</el-dialog>
		<company :show="showCompany" v-if="showCompany" v-on:close="showCompany=false" v-on:insert="insert"></company>
	</div>
</template>
<script>
	import company from '../../insPlugins/company.vue'
	import moment from 'moment'
	export default {
		data: function() {
			return {
				statusFlog:false,
				action: this.API_ROOT + "/base/execl/upload",
				upData: {
					schemeId: 'ff8081815e94f319015e98cbdc85530e',
					uid: window.localStorage.getItem("uid"),
					token: window.localStorage.getItem("token")
				},
				//
				warehouseID: "",
				companyID: "",
				//仓库下拉
				warehouse: [],

				inventoryTypeConvertData: {},
				inventoryResult: [],

				//列表与详情切换的标识
				tableFlog: true,
				//修改金额的form
				comFormDataPrice: {
					id: [],
					price: "",
				},
				//日期查询条件
				data: {
					firstStart: "",
					firstStarts: ""
				},

				//页码数
				CurentPage: 1,
				//详情页码数
				CurentPages: 1,
				//每页的数量
				page: this.page,

				//页码数
				CurentPageCar: 1,
				//每页的数量
				pageCar: this.page,
				//公司数据
				tableDataCar: {
					total: 0,
					dataList: []
				},

				//公司数据
				tableData: {
					total: 0,
					dataList: []
				},
				//佣金数据
				//分组数据
				tableDatas: {
					total: 0,
					dataList: []
				},

				conditions: {
					startDate: "",
					stopDate: "",
					warehouse: "",
					result: "",
				},

				conditionCar: {
					inventoryId: "",
					vin: '',
					carModel: '',
				},
				comFormShow: false,
				showCompany: false,
				makeComFormShow: false,
				prientFormShow: false,
				//校验规则
				RuleInventory: {
					inventoryDate: [{
						required: true,
						message: '请输入盘点时间',
						trigger: 'blur'
					}],

					result: [{
						required: true,
						message: '请输入盘点结果',
						trigger: 'blur'
					}],
					resultReason: [{
						required: true,
						message: '请输入盘点原因',
						trigger: 'blur'
					}],
				},
				//校验规则
				Rules: {},
				comFormData: {
					id: '',
					taskName: '',
					carCount: '',
					warehouseId: '',
					result: '',
					resultReason: '',
					taskStatus: '',
					makeResult: '',
					inventoryDate: '',
					company: "",
					locationId: "",
					companyId: "",
				},
				emptyData: {
					id: '',
					taskName: '',
					carCount: '',
					warehouseId: '',
					result: '',
					resultReason: '',
					inventoryDate: '',
					company: "",
					locationId: "",
					companyId: "",
				},
				comForm: {
					vin: [],
					inventoryId: "",
				},
				comFormReason: {
					vin: [],
					inventoryId: "",
					reason: "",
				},
				carMultipleSelection: [],
				makeMultipleSelection: [],
				multipleSelection: [],
				multipleSelections: [],
				company: "",
				//locationId:"",
				//发票金额显示框
				editFormShow: false,
				infoId: "",
				vin: '',
				carModel: '',
				warehouseId: '',
				//待打印车辆列表
				prientList: [],
				Rule: {
					taskName: [{
						required: true,
						message: '请输入盘点名称',
						trigger: 'blur'
					}],

				},
				dictTreeSearchValue: "",
				paramTreeData: [],
				//树型数据配置
				defaultProps: {
					children: 'child',
					label: 'label',
				},
				showStart: false,
				makeComFormReasonShow: false,
				levelConvertData: {},
			}
		},
		components: {
			company
		},
		methods: {
			process: function() {
				this.$data.loadingVue = this.$loading({
					fullscreen: true,
					text: "正在导入数据，请稍候"
				});
			},
			error: function(err, response) {
				this.$message.error(response.data.msg);
				this.$data.loadingVue.close();
			},
			success: function(response) {
				this.$data.loadingVue.close();
				if(response.success) {
					debugger;
					this.impCar();
					this.$message(response.msg);
				} else {
					this.$message.error(response.msg);
				}
			},
			//从临时表导入盘点
			impCar: function() {
				debugger;
				this.$http.get(this.API_ROOT + '/scm/inventory/importCar', {
					params: {
						inventoryId: this.$data.infoId
					}
				}).then((resp) => {
					debugger;
					this.$message(resp.data.msg);
					this.inventoryCarQuery();
				}, (resp) => {
					this.$message.error(resp.data.msg);
					// error callback
				});
			},
			downloadOrder: function() {
				window.location.href = this.API_ROOT + '/scm/inventory/exportCar?uid=' + window.localStorage.getItem("uid") + "&inventoryId=" + this.$data.infoId;
			},
			//所在位置转换
			locationCov: function(row, column) {
				return this.$data.levelConvertData[row.warehouseName];
			},
			//仓库转换转换
			warehouseCovert: function() {
				this.$http.get(this.API_ROOT + '/scm/warehouse/convert', {
					params: {}
				}).then((response) => {
					this.$data.levelConvertData = response.data;
				}, (response) => {});
			},

			//打开车型车系选择
			handleIconClick: function() {
				this.$data.showStart = true;
			},

			handleIconClickCompany: function() {
				this.$data.showCompany = true;
			},

			//查询树节点
			searchTree: function() {
				if(this.$data.dictTreeSearchValue == "") {
					this.$message("请输入查询条件");
					this.queryParamTree();
					return;
				}
				this.$refs.dictTree.filter(this.$data.dictTreeSearchValue);
			},

			//点击资源树节点
			handleNodeClick(data) {
				debugger;
				this.$data.carType = data.type;
				this.$data.datalabel = data.label;
				this.$data.datavale = data.value;
			},
			//查询参数树
			queryParamTree: function() {
				//获取资源树
				debugger;
				this.$http.get(this.API_ROOT + '/base/car/tree', {

				}).then((response) => {
					this.$data.paramTreeData = response.data;
				}, (response) => {});
			},
			//资源过滤
			filterNode: function(value, data, node) {
				if(!value) return true;
				return data.label.indexOf(value) !== -1;
			},

			//确认车型
			saveCarSerices: function() {
				debugger;
				if(this.$data.carType == '2') {
					this.$data.conditionCar.carModel = this.$data.datalabel;
				} else {
					this.$message("未选中车型");
				}
				this.$data.showStart = false;
			},

			//返回列表
			buckList: function() {
				this.$data.tableFlog = true;
				this.companyQuery();
				this.conutNum();
			},
			conutNum: function() {
				this.$http.get(this.API_ROOT + '/scm/inventoryDetail/countInventoryCar', {
					params: {
						id: this.$data.infoId
					}
				}).then((resp) => {
					debugger;
					this.$message(resp.data.msg);
					this.companyQuery();
				}, (resp) => {
					this.$message.error(resp.data.msg);
					// error callback
				});
			},
			//锁定盘点
			lock:function(){
				this.$http.get(this.API_ROOT + '/scm/inventory/confirmInventory', {
					params: {
						inventoryId: this.$data.infoId
					}
				}).then((resp) => {
					debugger;
					this.$message(resp.data.msg);
					this.companyQuery();
				}, (resp) => {
					this.$message.error(resp.data.msg);
					// error callback
				});
			},
			//根据是否盘点改变表格颜色
			tableRowClassName(row, index) {
				if(row.taskStatus == '0') {
					return 'day-row';
				} else {
					return '';
				}
			},

			//处理盘点结果
			makeResult: function() {
				debugger;
				if(this.$data.makeMultipleSelection.length == 1) {
					var resRoleData = this.$data.makeMultipleSelection[0];
					this.$http.get(this.API_ROOT + '/scm/inventory/info', {
						params: {
							id: resRoleData.id
						}
					}).then((response) => {
						debugger;
						this.$data.comFormData = Object.assign(this.$data.comFormData, response.data.data);

					}, (response) => {

						// error callback
					});
					this.$data.makeComFormShow = true;
				} else {
					this.$message.error("请选择一条数据");
				}
			},

			//查询库存车辆数
			carCountQuery: function(val) {
				debugger;
				this.$http.get(this.API_ROOT + '/scm/inventory/carCount', {
					params: {
						locationId: val,
						//locationId:this.$data.comFormData.locationId
						//this.$data.comFormData.locationId,
						//companyId:val					
					}
				}).then(resp => {
					if(resp.data.success) {
						// es5写法
						debugger;
						this.$data.comFormData.carCount = resp.data.data.carCount;
					} else {
						//debugger;
						this.$message.error(resp.data.msg);
					}
				}, resp => {});
			},

			//单位选择的回调
			insert: function(val, lable) {

				debugger;
				this.$data.comFormData.locationId = val;
				this.$data.companyID = lable;
				this.carCountQuery(val[0]);
				this.$data.warehouseID = "";

			},

			//			//查询库存车辆数
			//			companyCarCountQuery: function(val) {
			//				this.$http.get(this.API_ROOT + '/scm/inventory/carCount', {
			//					params: {						
			//						companyId: val						
			//					}
			//				}).then(resp => {
			//					if(resp.data.success) {
			//						// es5写法
			//						debugger;
			//						this.$data.comFormData.carCount = resp.data.data.carCount;
			//					} else {
			//						//debugger;
			//						this.$message.error(resp.data.msg);
			//					}
			//				}, resp => {});
			//			},
			//			
			locationChange: function(val) {
				debugger;
				if(val != "") {
					this.carCountQuery(val);
					this.$data.comFormData.locationId = val;
					this.$data.companyID = "";
				}
			},
			//			companyChange:function(val){
			//				this.carCountQuery(val);
			//			},

			//加入待打印列表
			addPrient: function() {
				debugger;
				if(this.$data.prientList.length == 0) {
					this.$data.prientList = this.$data.carMultipleSelection;
				} else {
					//根据vin判断，防止重复添加
					for(var i = 0; i < this.$data.carMultipleSelection.length; i++) {
						for(var j = 0; j < this.$data.prientList.length; j++) {
							if(this.$data.carMultipleSelection[i].vin = this.$data.prientList[j].vin) {
								//从carMultipleSelection中移除角标为i的元素
								this.$data.carMultipleSelection.splice(i, 1);
								break;
							}
						}
					};
					debugger;
					this.$data.prientList = this.$data.prientList.concat(this.$data.carMultipleSelection);
					this.$data.carMultipleSelection = [];
				}
				this.$message("已加入列表");
			},

			//正常盘点结果录入
			addInventoryResultRight: function() {
				debugger;
				this.$data.comForm.vin = [];
				for(var i = 0; i < this.$data.carMultipleSelection.length; i++) {
					this.$data.comForm.vin[i] = this.$data.carMultipleSelection[i].vin
				}
				//this.$data.comForm.vins = this.$data.carMultipleSelection;
				if(this.$data.carMultipleSelection.length > 0) {
					this.$http.post(this.API_ROOT + '/scm/inventory/updateRight', this.$data.comForm, {
							params: {}
						})
						.then(resp => {
							if(resp.data.success) {
								debugger;
								this.inventoryCarQuery();
								//this.$data.addFormShow = false;
							} else {
								this.$message.error(resp.data.msg);
							}
						}, resp => {});
				} else {
					this.$message.error("请选择车辆！");
				}
			},
			//更改盘库的状态
			addDifferenceReason: function() {
				debugger;
				this.$data.comFormReason.vin = [];
				for(var i = 0; i < this.$data.carMultipleSelection.length; i++) {
					this.$data.comFormReason.vin[i] = this.$data.carMultipleSelection[i].vin
				}
				//this.$data.comForm.vin = this.$data.carMultipleSelection;
				if(this.$data.carMultipleSelection.length > 0) {
					this.$http.post(this.API_ROOT + '/scm/inventory/updateError', this.$data.comFormReason, {
							params: {}
						})
						.then(resp => {
							if(resp.data.success) {
								debugger;
								this.inventoryCarQuery();
								this.$data.makeComFormReasonShow = false;
							} else {
								this.$message.error(resp.data.msg);
								return false;
							}
						}, resp => {});

				} else {
					this.$message.error("请选择车辆！");
				}
			},

			addDifference: function() {
				if(this.$data.carMultipleSelection.length > 0) {
					this.$data.makeComFormReasonShow = true;
				} else {
					this.$message.error("请选择一条或多条数据");
				}
			},
			//录入盘点
			saveDifferenceReason: function() {
				this.$data.comFormReason.vins = this.$data.carMultipleSelection;
				if(this.$data.carMultipleSelection.length > 0) {
					this.$http.post(this.API_ROOT + '/scm/stock/saveDifferenceReason', this.$data.comFormReason, {
							params: {}
						})
						.then(resp => {
							if(resp.data.success) {
								this.inventoryCarQuery();
								this.$data.makeComFormReasonShow = false;
							} else {
								this.$message.error(resp.data.msg);
							}
						}, resp => {});

				} else {
					this.$message.error("请选择一条数据");
				}
			},
			//保存已选择的车辆、仓库ID和入库时间
			saveCar: function() {
				debugger;
				this.$data.formData.multipleSelectionCar = this.$data.multipleSelection;
				this.$data.formData.addFormData.enterDate = this.moment(this.$data.formData.addFormData.enterDate).format("YYYY-MM-DD");
				this.$http.post(this.API_ROOT + '/scm/stock/save', this.$data.formData, {
						params: {
							type: '0',
						}
					})
					.then(resp => {
						if(resp.data.success) {
							debugger;
							this.query();
							this.$data.addFormShow = false;
						} else {
							this.$message.error(resp.data.msg);
						}
					}, resp => {});
			},

			//打印盘点单
			prientOrder: function() {
				this.$data.prientFormShow = true;
			},

			//打印车辆
			savePrient: function() {
				if(this.$data.prientList.length < 1) {
					this.$message.error("请选择车辆");
				} else {
					this.$confirm('确认要打印吗?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						var data = [];
						for(var i = 0; i < this.$data.prientList.length; i++) {
							data[i] = this.$data.prientList[i].vin
						}
						this.$http.post(this.API_ROOT + '/scm/inventoryDetail/printInventoryDetail', data, {
							params: {
								id: this.$data.infoId,
							}
						}).then((response) => {
							this.$message(response.data.msg);
							//this.query();
							this.inventoryCarQuery();
							this.$data.prientList = [];
							this.$data.prientFormShow = false;
						}, (response) => {});
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '已取消此操作'
						});
					});
				}
			},

			//选择框
			handleSelectionChange: function(val) {
				debugger;
				this.$data.multipleSelection = val;
			},
			//处理盘点结果选择框
			makeHandleSelectionChange: function(val) {
				debugger;
				this.$data.makeMultipleSelection = val;
			},

			carHandleSelectionChange: function(val) {
				debugger;
				this.$data.carMultipleSelection = val;
			},

			add: function() {
				this.$data.comFormData = Object.assign(this.$data.comFormData, this.$data.emptyData);
				this.$data.comFormShow = true;
			},

			//查询盘点任务列表
			companyQuery: function() {
				//开始时间
				this.$data.conditions.startDate = this.momentFu(this.$data.data.firstStart);
				//结束时间
				this.$data.conditions.stopDate = this.momentFu(this.$data.data.firstStarts);
				this.$http.post(this.API_ROOT + '/scm/inventory/page', this.$data.conditions, {
					params: {
						start: this.$data.CurentPage,
						limit: this.$data.page.pageSize
					}
				}).then(resp => {
					if(resp.data.success) {
						resp.data.total = parseInt(resp.data.total);
						// es5写法
						this.$data.tableData = resp.data;
						//this.baseQuery(this.$data.curTreeDeptId);
						//this.$data.exFormShow = false;
					} else {
						//debugger;
						this.$message.error(resp.data.msg);
					}
				}, resp => {});
			},
			//时间判断为空的封装
			momentFu: function(dt) {
				if(dt == '' || dt == null || dt == undefined) {
					return "";
				} else {
					return this.moment(dt).format("YYYY-MM-DD");
				}
			},

			//查询盘点任务的车辆
			inventoryCarQuery: function() {
				debugger;
				//this.$data.warehouseId = this.$data.tableData.dataList[index].warehouseId; 
				this.$http.post(this.API_ROOT + '/scm/inventory/carPage', this.$data.conditionCar, {
					params: {
						start: this.$data.CurentPages,
						limit: this.$data.page.pageSize,
						warehouseId: this.$data.warehouseId
					}
				}).then(resp => {
					resp.data.total = parseInt(resp.data.total);
					this.$data.tableDatas = resp.data;
					//this.mounthPrice();
				}, resp => {});
			},
			//查看盘点任务详情
			info: function(index) {
				if(this.$data.tableData.dataList[index].makeResult=="0"){
					debugger;
					this.$data.statusFlog=true;
				}else{
					this.$data.statusFlog=false;
				}
				this.$data.conditionCar.inventoryId = this.$data.tableData.dataList[index].id;
				this.$data.infoId = this.$data.tableData.dataList[index].id;
				this.$data.comForm.inventoryId = this.$data.tableData.dataList[index].id;
				this.$data.comFormReason.inventoryId = this.$data.tableData.dataList[index].id;
				this.$data.warehouseId = this.$data.tableData.dataList[index].warehouseId;
				this.inventoryCarQuery();
				this.$data.tableFlog = false;
			},
			//保存
			save: function() {
				debugger;
				this.$data.comFormData.inventoryDate = this.moment(this.$data.comFormData.inventoryDate).format("YYYY-MM-DD");

				this.$http.post(this.API_ROOT + '/scm/inventory/save', this.$data.comFormData)
					.then(resp => {
						if(resp.data.success) {
							debugger;
							this.companyQuery();
							this.$data.comFormShow = false;
							this.$data.makeComFormShow = false;
							this.$message(resp.data.msg);
						} else {
							this.$message.error(resp.data.msg);
						}
					}, resp => {});
			},

			update: function() {
				debugger;
				this.$data.comFormData.inventoryDate = this.moment(this.$data.comFormData.inventoryDate).format("YYYY-MM-DD");

				this.$http.post(this.API_ROOT + '/scm/inventory/update', this.$data.comFormData)
					.then(resp => {
						if(resp.data.success) {
							debugger;
							this.companyQuery();
							this.$data.comFormShow = false;
							this.$data.makeComFormShow = false;
							this.$message(resp.data.msg);
						} else {
							this.$message.error(resp.data.msg);
						}
					}, resp => {});
			},

			//任务状态
			taskStatusCov: function(row, column) {
				return row.taskStatus == "0" ? '未盘点' : '已盘点';
			},
			//盘点结果处理
			makeResultCov: function(row, column) {
				if(row.result == "0") {
					return '未处理';
				}
				if(row.result == "1") {
					return '已处理';
				}

			},
			//盘点结果
			resultCov: function(row, column) {
				return row.result;
//				if(row.result == "0") {
//					return '未通过';
//				}
//				if(row.result == "1") {
//					return '已通过';
//				}

			},

			//列表，分页大小切换
			handleSizeChange: function() {},
			//列表,当前页切换
			handleCurrentChange: function(currentPage) {
				this.$data.CurentPage = currentPage;
				//this.$data.dictGroup = '';
				this.companyQuery();
			},
			//详情页页码切换
			handleCurrentChanges: function(currentPage) {
				this.$data.CurentPages = currentPage;
				//this.$data.dictGroup = '';
				this.inventoryCarQuery();
			},
			//列表，分页大小切换
			handleSizeChangeCar: function() {},
			//列表,当前页切换
			handleCurrentChangeCar: function(currentPage) {
				this.$data.CurentPageCar = currentPage;
				//this.$data.dictGroup = '';
				this.carQuery();
			},

			//盘点结果类型解析
			//			inventoryTypeCov: function(row, column) {
			//				return this.$data.inventoryTypeConvertData[row.differenceType];
			//			},
			inventoryTypeCovert: function() {
				this.$http.get(this.API_ROOT + '/base/dict/convert', {
					params: {
						group: "scmInventoryType"
					}
				}).then((response) => {
					this.$data.inventoryTypeConvertData = response.data;
				}, (response) => {});
			},
		},
		//表单创建时执行
		created: function() {
			this.warehouseCovert();
			this.inventoryTypeCovert();
			this.companyQuery();
			this.queryParamTree();
			//仓库下拉
			this.$http.get(this.API_ROOT + '/scm/warehouse/combo', {
				params: {}
			}).then((response) => {
				this.$data.warehouse = response.data;
			}, (response) => {});
			//盘点结果下拉
			this.$http.get(this.API_ROOT + '/base/dict/combo', {
				params: {
					group: "scmInventory"
				}
			}).then((response) => {
				this.$data.inventoryResult = response.data;
			}, (response) => {});

		}
	}
</script>
<style>
	.el-table .info-row {
		height: 10px !important;
	}
	
	.item {
		width: 30px;
	}
	
	.el-form-item {
		clear: both;
	}
	
	.el-dropdown .el-button-group,
	.el-table .el-tooltip,
	.el-table .el-tooltip__rel {
		display: inline;
	}
	
	.el-table {
		height: 100%;
		width: 100%;
	}
	
	#el-select {
		width: 200px;
	}
	
	.day-row {
		background: #FF4949;
	}
	
	.table_input {
		border-style: none;
		outline: medium;
		width: 100%;
		height: 100%;
	}
</style>